#!/bin/bash
# 获取激活码绑定设备
# 安装依赖软件包
# sudo apt install uuid curl jq

API_URL="https://api.tenclass.net/xiaozhi/ota/"
MACADDR=$(ip link show | awk '/link\/ether/ {print $2;exit}')
JSON_DATA=$(cat <<EOF
{
    "application": {
        "version": "1.8.2"
    },
    "board": {
        "type": "bread-compact-wifi", 
        "name": "bread-compact-wifi",
	"ssid": "ssid",
	"rssi": 0
    }
}
EOF
)

CODE=$(curl -s -X POST \
    -H "Content-Type: application/json" \
    -H "Device-Id: $MACADDR" \
    -H "Client-Id: $(uuid)" \
    -H "User-Agent: bread-compact-wifi/1.8.2" \
    -d "$JSON_DATA" \
    "$API_URL" | jq -r '.activation.code'
)

if [ "$CODE" != "null" ]; then
    echo "激活码: $CODE"
else
    echo "已激活"
fi
